package net.lainiao.mycost.controller;

import net.lainiao.mycost.bean.RoleInfo;
import net.lainiao.mycost.utils.Comm;
import net.lainiao.mycost.utils.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2017/3/22.
 */
@Controller
@RequestMapping("/role/")
public class RoleController extends Page {
    @RequestMapping("list.do")
    public String list(RoleInfo info, Model model, HttpServletRequest request){
        if(info==null){
            info=new RoleInfo();
        }
        this.initPage(request);
        info.setStart(this.getPageNo());
        info.setLength(PAGE_NUM_BIG);
        model.addAttribute("list",roleInfoService.list(info));
        model.addAttribute("total",roleInfoService.getCount(info));
        return "role/role_list";
    }

    @RequestMapping("loadadd.do")
    public String loadadd(){
        return "role/role_add";
    }

    @RequestMapping("add.do")
    public String add(RoleInfo info,Model model,HttpServletRequest request){
        if(info==null){
            info=new RoleInfo();
        }
        info.setRoleMark(Comm.MARK_YES);
        roleInfoService.add(info);
        return list(null,model,request);
    }

    @RequestMapping("loadupdate.do")
    public String loadUpdate(RoleInfo info,Model model){
        model.addAttribute("role",roleInfoService.getInfo(info));
        return "role/role_update";
    }

    @RequestMapping("update.do")
    public String update(RoleInfo info,Model model,HttpServletRequest request){
        roleInfoService.update(info);
        return list(null,model,request);
    }

    @RequestMapping("delete.do")
    public String delete(Integer[] roleId,Model model,HttpServletRequest request){
        roleInfoService.delete(roleId);
        return list(null,model,request);
    }
}
